package com.vansoftwaredesign.widgetlibrary;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.Window;
import android.widget.TextView;

public class WidgetTestActivity extends Activity {
	
	//create an instance of the config object
	WidgetConfig myConfig = new WidgetConfig();
	//are we in debug mode 
	boolean inDebug = myConfig.inDebugMode();
	
	private static final String TAG = "WidgetTestActivity";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_widget_test);
		final JoyStickWidget leftJoyStick = (JoyStickWidget) findViewById(R.id.JoyStickView);
		final JoyStickWidget rightJoyStick = (JoyStickWidget) findViewById(R.id.JoyStickView2);
		final TextView leftText = (TextView) findViewById(R.id.leftStickText);
		final TextView rightText = (TextView) findViewById(R.id.rightStickText);
		
		
		JoystickMovedListener leftListener = new JoystickMovedListener() {
			
			@Override
			public void OnMoved(float pan, float tilt) {
				float x = leftJoyStick.getNormalizedX();
				float y = leftJoyStick.getNormalizedY();
				Log.d("leftStickListener", "pan " + pan + " tilt " + tilt + " x " + x + " y " + y);
				leftText.setText("x " + x + " y " + y);
				
			}

			@Override
			public void OnReleased() {
				// TODO Auto-generated method stub
				float x = leftJoyStick.getNormalizedX();
				float y = leftJoyStick.getNormalizedY();
				//Log.d("leftStickListener", "pan " + pan + " tilt " + tilt + " x " + x + " y " + y);
				leftText.setText("x " + x + " y " + y);
				
			}

			@Override
			public void OnReturnedToCenter() {
				// TODO Auto-generated method stub
				float x = leftJoyStick.getNormalizedX();
				float y = leftJoyStick.getNormalizedY();
				//Log.d("leftStickListener", "pan " + pan + " tilt " + tilt + " x " + x + " y " + y);
				leftText.setText("x " + x + " y " + y);
				
			}
		};
		
		leftJoyStick.setMoveListener(leftListener);
		
		JoystickMovedListener rightListener = new JoystickMovedListener() {
			
			@Override
			public void OnMoved(float pan, float tilt) {
				// TODO Auto-generated method stub
				float x = rightJoyStick.getNormalizedX();
				float y = rightJoyStick.getNormalizedY();
				//Log.d("rightStickListener", "pan " + pan + " tilt " + tilt + " x " + x + " y " + y);
				rightText.setText("x " + x + " y " + y);
				
			}

			@Override
			public void OnReleased() {
				// TODO Auto-generated method stub
				float x = rightJoyStick.getNormalizedX();
				float y = rightJoyStick.getNormalizedY();
				//Log.d("rightStickListener", "pan " + pan + " tilt " + tilt + " x " + x + " y " + y);
				rightText.setText("x " + x + " y " + y);
				
			}

			@Override
			public void OnReturnedToCenter() {
				// TODO Auto-generated method stub
				float x = rightJoyStick.getNormalizedX();
				float y = rightJoyStick.getNormalizedY();
				//Log.d("rightStickListener", "pan " + pan + " tilt " + tilt + " x " + x + " y " + y);
				rightText.setText("x " + x + " y " + y);
				
			}
		};
		
		rightJoyStick.setMoveListener(rightListener);
		
//		leftJoyStickListener = new OnTouchListener() {
//			
//			@Override
//			public boolean onTouch(View v, MotionEvent event) {
//				// TODO Auto-generated method stub
//				return false;
//			}
//		};
//		
//		leftJoyStick.setOnTouchListener(leftJoyStickListener);
		
		initTest();
	}
	

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_widget_test, menu);
		return true;
	}

	//initialize the widget test activity
	private void initTest() {
		
		if(inDebug) { Log.d(TAG,"WidgetLibrary Test Activity initTest called."); } 
		myConfig.toast("Test Toast", getApplicationContext());
	}
	
}
